// 当前游戏id
var curMatchId = parseInt(getParam('curMatchId'));

// 当前游戏是否为热门
var curMatchIsHot = parseInt(getParam('isHot'));

// 当前选中的li的index
var curFocusLi =  parseInt(getParam('focusLiIdx'));

// 记录当前5个container的第一行的id
var firRowIds = curMatchIsHot == 1 ? ['re_firRow','allVideo_1','hot_match_1','anchor_1','album_1'] : ['allVideo_1','hot_match_1','anchor_1','album_1'];

// 记录当前5个container的id
var speContainerIDs = curMatchIsHot == 1 ? ['recommends','all_container','hot_container','anchor_container','album_container'] : ['all_container','hot_container','anchor_container','album_container'];
function getContainers(){
  var contArrs = new Array();
  for(var i = 0; i < speContainerIDs.length; i++){
    contArrs[i] = document.getElementById(speContainerIDs[i]);
  }
  return contArrs;
}
var containersArr = getContainers();

// 获取当前leftmenu所在的页面
function getLeftMenuPageIdx(){
  for(var pageIdx = 0; pageIdx < speContainerIDs.length; pageIdx++){
    if (containersArr[pageIdx].style.display == "block") {
      return pageIdx;
    }
  }
}

// leftMenu 默认idx
var curMenuIdx;
// leftMenu 类型
var curMenuType = curMatchIsHot == 1 ? 0 : 2;

// 设置选中第几个模块
if (curFocusLi == 1) {
  curMenuIdx = 0;
  getObjById(speContainerIDs[curFocusLi-1]).style.display = "block";
}else if (curFocusLi == 3) {
  curFocusLi = curMatchIsHot == 1 ? 3 : 2;
  curMenuIdx = curMatchIsHot == 1 ? 2 : 1;
  getObjById(speContainerIDs[curFocusLi-1]).style.display = "block";
}

// 总的li的数量
var totalMenuLiNum = speContainerIDs.length;
// 5个模块的数组
var matchs,recommendArrs,allVideos,hotmacths,anchors,albums;



matchs = [
   {id:0,logo:'../image/test/spd_logo.png',bg:'../image/test/spd_bg.png'}
  ,{id:1,logo:'../image/test/spd_logo.png',bg:'../image/test/spd_bg.png'}
];

recommendArrs = [
   {id:'0',intro:'kpl',title:'2018王者荣耀KPL春季赛 预选赛',imgSrc:'../image/test/match.png'}
  ,{id:'1',intro:'CFPL',title:'2018CFPL',imgSrc:'../image/test/team1.png'}
  ,{id:'2',intro:'王者荣耀',title:'王者荣耀全民赛',imgSrc:'../image/test/team2.png'}
  ,{id:'3',intro:'战队',title:'AG超玩会',imgSrc:'../image/test/team3.png'}
  ,{id:'4',intro:'英雄周报',title:'【英雄周报】王者荣耀新版后羿',imgSrc:'../image/test/anchor1.png'}
  ,{id:'5',intro:'鱼嘴滑舌',title:'美人鱼头鱼嘴滑舌',imgSrc:'../image/test/anchor2.png'}
  ,{id:'6',intro:'主播',title:'王者荣耀瓶子教学',imgSrc:'../image/test/anchor3.png'}
];

allVideos = [
   {id:0,title:'2018王者荣耀KPL春季赛预选赛\nQGhappy vs eStar',imgSrc:'../image/test/video1.png'}
  ,{id:1,title:'【鱼嘴滑舌】盘点 第12期：哪些影响有真实伤害',imgSrc:'../image/test/video1.png'}
  ,{id:2,title:'【鱼嘴滑舌】第89期：无畏战车狂铁，极限反击以一敌五',imgSrc:'../image/test/video1.png'}
  ,{id:3,title:'【上分拍档】第24期：弈星+苏烈控场法王一招致胜',imgSrc:'../image/test/video1.png'}
  ,{id:4,title:'【破冰英雄】盘点 第12期：哪些影响有真实伤害',imgSrc:'../image/test/video1.png'}
  ,{id:5,title:'【上分拍档】第24期：弈星+苏烈控场法王一招致胜',imgSrc:'../image/test/video1.png'}
  ,{id:6,title:'2018王者荣耀KPL春季赛预选赛 QGhappy vs eStar',imgSrc:'../image/test/video1.png'}
  ,{id:7,title:'【鱼嘴滑舌】第89期：无畏战车狂铁，极限反击以一敌五',imgSrc:'../image/test/video1.png'}
  ,{id:8,title:'2018王者荣耀KPL春季赛预选赛 QGhappy vs eStar',imgSrc:'../image/test/video1.png'}
  ,{id:9,title:'【鱼嘴滑舌】盘点 第12期：哪些影响有真实伤害',imgSrc:'../image/test/video1.png'}
  ,{id:10,title:'【鱼嘴滑舌】第89期：无畏战车狂铁，极限反击以一敌五',imgSrc:'../image/test/video1.png'}
  ,{id:11,title:'【上分拍档】第24期：弈星+苏烈控场法王一招致胜',imgSrc:'../image/test/video1.png'}
  ,{id:12,title:'【破冰英雄】盘点 第12期：哪些影响有真实伤害',imgSrc:'../image/test/video1.png'}
  ,{id:13,title:'【上分拍档】第24期：弈星+苏烈控场法王一招致胜',imgSrc:'../image/test/video1.png'}
  ,{id:14,title:'2018王者荣耀KPL春季赛预选赛 QGhappy vs eStar',imgSrc:'../image/test/video1.png'}
  // ,{id:15,title:'【鱼嘴滑舌】第89期：无畏战车狂铁，极限反击以一敌五',imgSrc:'../image/test/video1.png'}
];

hotMatchs = [
   {id:0,title:'2018CFPL',imgSrc:'../image/test/hotmacths/1.png'}
  ,{id:1,title:'王者荣耀全民赛',imgSrc:'../image/test/hotmacths/3.png'}
  ,{id:2,title:'2017王者高校联赛',imgSrc:'../image/test/hotmacths/2.png'}
  ,{id:3,title:'2018KPL春季赛',imgSrc:'../image/test/hotmacths/5.png'}
  ,{id:3,title:'LPL职业联赛',imgSrc:'../image/test/hotmacths/4.png'}
  ,{id:4,title:'2017王者高校联赛',imgSrc:'../image/test/hotmacths/2.png'}
  ,{id:8,title:'LPL职业联赛',imgSrc:'../image/test/hotmacths/4.png'}
  ,{id:5,title:'2018CFPL',imgSrc:'../image/test/hotmacths/1.png'}
  ,{id:7,title:'王者荣耀全民赛',imgSrc:'../image/test/hotmacths/3.png'}
  ,{id:9,title:'2018KPL春季赛',imgSrc:'../image/test/hotmacths/5.png'}
  ,{id:3,title:'2018KPL春季赛',imgSrc:'../image/test/hotmacths/5.png'}
  ,{id:3,title:'LPL职业联赛',imgSrc:'../image/test/hotmacths/4.png'}
  ,{id:4,title:'2017王者高校联赛',imgSrc:'../image/test/hotmacths/2.png'}
];

anchors = [
   {id:0,title:'零度',imgSrc:'../image/test/anchor/1.png'}
  ,{id:1,title:'瓶子',imgSrc:'../image/test/anchor/2.png'}
  ,{id:2,title:'美人鱼头',imgSrc:'../image/test/anchor/3.png'}
  ,{id:3,title:'板娘',imgSrc:'../image/test/anchor/4.png'}
  ,{id:1,title:'瓶子',imgSrc:'../image/test/anchor/2.png'}
  ,{id:2,title:'美人鱼头',imgSrc:'../image/test/anchor/3.png'}
  ,{id:3,title:'板娘',imgSrc:'../image/test/anchor/4.png'}
  ,{id:1,title:'瓶子',imgSrc:'../image/test/anchor/2.png'}
  ,{id:2,title:'美人鱼头',imgSrc:'../image/test/anchor/3.png'}
  ,{id:3,title:'板娘',imgSrc:'../image/test/anchor/4.png'}
  ,{id:1,title:'瓶子',imgSrc:'../image/test/anchor/2.png'}
  ,{id:2,title:'美人鱼头',imgSrc:'../image/test/anchor/3.png'}
  ,{id:3,title:'板娘',imgSrc:'../image/test/anchor/4.png'}
  ,{id:1,title:'瓶子',imgSrc:'../image/test/anchor/2.png'}
  ,{id:2,title:'美人鱼头',imgSrc:'../image/test/anchor/3.png'}
  ,{id:3,title:'板娘',imgSrc:'../image/test/anchor/4.png'}
];

// 精选专辑
var albums = [
   {id:0,title:'零度',imgSrc:'../image/test/anchor/1.png'}
  ,{id:1,title:'瓶子',imgSrc:'../image/test/anchor/2.png'}
  ,{id:2,title:'美人鱼头',imgSrc:'../image/test/anchor/3.png'}
  ,{id:3,title:'板娘',imgSrc:'../image/test/anchor/4.png'}
  ,{id:4,title:'王者荣耀全民赛',imgSrc:'../image/test/hotmacths/3.png'}
  ,{id:1,title:'2017王者高校联赛',imgSrc:'../image/test/hotmacths/2.png'}
  ,{id:3,title:'LPL职业联赛',imgSrc:'../image/test/hotmacths/4.png'}
  ,{id:5,title:'2018CFPL',imgSrc:'../image/test/hotmacths/1.png'}
  ,{id:8,title:'王者荣耀全民赛',imgSrc:'../image/test/hotmacths/3.png'}
  ,{id:9,title:'2018KPL春季赛',imgSrc:'../image/test/hotmacths/5.png'}
  ,{id:3,title:'LPL职业联赛',imgSrc:'../image/test/hotmacths/4.png'}
  ,{id:5,title:'2018CFPL',imgSrc:'../image/test/hotmacths/1.png'}
  ,{id:8,title:'王者荣耀全民赛',imgSrc:'../image/test/hotmacths/3.png'}
  ,{id:9,title:'2018KPL春季赛',imgSrc:'../image/test/hotmacths/5.png'}
];

// 设置背景图
document.getElementById('matchDiv').style.backgroundImage = 'url('+ matchs[0]['bg'] +')';
document.getElementById('matchLogo').style.backgroundImage = 'url('+ matchs[0]['logo'] +')';

/************** 热门推荐 start **************/
  var re_videosArr = document.getElementsByClassName('re_videos');
  for(var i = 0; i < re_videosArr.length; i++){
    re_videosArr[i].style.backgroundImage = 'url('+ recommendArrs[i]['imgSrc'] +')';
    re_videosArr[i].innerHTML = '<p>'+ recommendArrs[i]['title'] +'</p>';
  }
/************** 热门推荐 end **************/

/************** 所有视频 start **************/
  var allVideosRow = Math.ceil(allVideos.length / 4);
  var allVideos_innerHtml = '';
  for(var i = 1; i <= allVideosRow; i++){
    allVideos_innerHtml += '<div id="allVideo_'+ i +'" class="videoDiv"></div>';
  }
  document.getElementById('allVideos').innerHTML = allVideos_innerHtml;

  for(var j = 1; j <= allVideos.length; j++){
    var curRowIdx = Math.ceil(j/4);
    var curDivID = 'allVideo_' + curRowIdx;
    document.getElementById(curDivID).innerHTML += '<div id="all_video_list_'+ j +'" class="all_video" style="background-image:url('+ allVideos[j-1]['imgSrc'] +')"><div><p>'+ allVideos[j-1]['title'] +'</p></div></div>';
  }
/************** 所有视频 end **************/

/************** 热门赛事 start **************/
  var hotMatchsRow = Math.ceil(hotMatchs.length / 5);
  var hotMatchs_innerHtml = '';
  for(var i = 1; i <= hotMatchsRow; i++){
    hotMatchs_innerHtml += '<div id="hot_match_'+ i +'" class="hotDiv"></div>';
  }
  document.getElementById('hotMatch').innerHTML = hotMatchs_innerHtml;

  for(var j = 1; j <= hotMatchs.length; j++){
    var curRowIdx = Math.ceil(j/5);
    var curDivID = 'hot_match_' + curRowIdx;
    var curHMInner = '';
    if (j % 5 == 1) {
      curHMInner = '<div id="hot_match_list_'+ j +'" class="hot_match firRow" style="background-image:url('+ hotMatchs[j-1]['imgSrc'] +')"><p>'+ hotMatchs[j-1]['title'] +'</p></div>';
    }else{
      curHMInner = '<div id="hot_match_list_'+ j +'" class="hot_match" style="background-image:url('+ hotMatchs[j-1]['imgSrc'] +')"><p>'+ hotMatchs[j-1]['title'] +'</p></div>';
    }
    document.getElementById(curDivID).innerHTML += curHMInner;
  }
/************** 热门赛事 end **************/

/************** 主播大神 start **************/
  var anchorsRow = Math.ceil(anchors.length / 5);
  var anchors_innerHtml = '';
  for(var i = 1; i <= anchorsRow; i++){
    anchors_innerHtml += '<div id="anchor_'+ i +'" class="anchorDiv"></div>';
  }
  document.getElementById('anchors').innerHTML = anchors_innerHtml;

  for(var j = 1; j <= anchors.length; j++){
    var curRowIdx = Math.ceil(j/5);
    var curDivID = 'anchor_' + curRowIdx;
    var curAncInner = '';
    if (j % 5 == 1) {
      curAncInner = '<div id="anchor_list_'+ j +'" class="anchor firRow" style="background-image:url('+ anchors[j-1]['imgSrc'] +')"><p>'+ anchors[j-1]['title'] +'</p></div>';
    }else{
      curAncInner = '<div id="anchor_list_'+ j +'" class="anchor" style="background-image:url('+ anchors[j-1]['imgSrc'] +')"><p>'+ anchors[j-1]['title'] +'</p></div>';
    }
    document.getElementById(curDivID).innerHTML += curAncInner;
  }
/************** 主播大神 end **************/

/************** 精选专辑 start **************/
  var albumsRow = Math.ceil(albums.length / 5);
  var albums_innerHtml = '';
  for(var i = 1; i <= albumsRow; i++){
    albums_innerHtml += '<div id="album_'+ i +'" class="albumDiv"></div>';
  }
  document.getElementById('albums').innerHTML = albums_innerHtml;

  for(var j = 1; j <= albums.length; j++){
    var curRowIdx = Math.ceil(j/5);
    var curDivID = 'album_' + curRowIdx;
    var curAlbInner = '';
    if (j % 5 == 1) {
      curAlbInner = '<div  id="album_list_'+ j +'" class="album firRow" style="background-image:url('+ albums[j-1]['imgSrc'] +')"><p>'+ albums[j-1]['title'] +'</p></div>';
    }else{
      curAlbInner = '<div  id="album_list_'+ j +'" class="album" style="background-image:url('+ albums[j-1]['imgSrc'] +')"><p>'+ albums[j-1]['title'] +'</p></div>';
    }
    document.getElementById(curDivID).innerHTML += curAlbInner;
  }
/************** 精选专辑 end **************/

/************************ 键盘触发事件 start ************************/
  document.onkeydown = focusEvent;
  var isClickEnter; // 是否按下回车
  var curActiveVideo = new Array(); // 当前右侧焦点对象
  var curMenuPageId; // 当前leftmenu选中的值
  var listDivClassName = ''; // 当前list中焦点的className
  var curKey = ''; // 当前的按键
  var curSelectedLi; // 记录被选中的menu中的li的id

  function focusEvent(e){
    // 获取leftMenu中的li的当前焦点的index
    var curActiveLi = document.getElementsByClassName('left_menu_active');
    var curLiIdx = parseInt(curActiveLi[0].id.replace('leftmenu_li_',''));
    
    curSelectedLi = isClickEnter == 'undefined' ? 1 : curLiIdx;

    // 获取分区中的焦点
    curMenuPageId = getLeftMenuPageIdx();
    // 获取右侧详情video焦点
    var curAllVideoIdx = curMenuType == 0 ? 1 : 0;    
    listDivClassName = curMenuPageId != curAllVideoIdx ? 'spd_curActive' : 'spd_curActiveVideo';

    curActiveVideo = document.getElementsByClassName(listDivClassName);

    e = e || window.event; //这一行及下一行是为兼容IE8及以下版本
    var curWhichKey = e.which;

    switch(curWhichKey){
      case 13: // 回车/OK
        isClickEnter == 1;
        if (curActiveVideo.length == 0) { // 只有左边菜单栏有焦点时
          // curLiIdx = parseInt(curActiveLi[0].id.replace('leftmenu_li_',''));
          // for(var i = 0; i < speContainerIDs.length; i++){
          //   containersArr[i].style.display = 'none';
          // }
          // containersArr[curLiIdx-1].style.display = "block";
        }else {
          
          if (curMenuPageId == 0 && curMenuType == 0) { // 热门推荐
            window.location.href = '../match/album_play.html';
          }else if ((curMenuPageId == 0 && curMenuType == 2) || (curMenuPageId == 1 && curMenuType == 0)) {
            
          }else if ((curMenuPageId == 1 && curMenuType == 2) || (curMenuPageId == 2 && curMenuType == 0)) {
            window.location.href = '../match/album_play.html';
          }else if ((curMenuPageId == 2 && curMenuType == 2) || (curMenuPageId == 3 && curMenuType == 0)) {
            window.location.href = '../anchor/anchorDetail.html';
          }else if ((curMenuPageId == 3 && curMenuType == 2) || (curMenuPageId == 4 && curMenuType == 0)) {
            window.location.href = '../match/album_play.html';
          }
        }
        break;

      case 27: // ESC
        window.history.back();
        break;

      case 37: // 左
        curKey = 'l';
        // 左侧内容列表中有焦点
        if (curActiveVideo.length != 0) {
          directionKeyFunc();
        }
        break;

      case 38: // 上
        curKey = 'u';
        if (curLiIdx != 1 && curActiveVideo.length == 0) { // 只有左边菜单栏有焦点时
          setLeftMenuLi(curLiIdx,(curLiIdx-1));

          for(var i = 0; i < speContainerIDs.length; i++){
            containersArr[i].style.display = 'none';
          }
          containersArr[curLiIdx-2].style.display = "block";
          // 设置focused
          setFocus('leftmenu_li_'+curLiIdx,'left_menu_only_focused','leftmenu_li_'+(curLiIdx-1),'left_menu_only_focused',2);
        }else if (curActiveVideo.length != 0) { // 左侧内容列表中有焦点
          directionKeyFunc();
        }
        break;

      case 39: // 右
        curKey = 'r';
        if (curActiveVideo.length == 0) { // 右边video无焦点时
          if (curMenuPageId == 0 && curMenuType == 0) {
            // 热门推荐
            setFocus('','','re_1',listDivClassName,1);
            setLeftMenuLi(curSelectedLi,(curMenuPageId+1));
          }else if ((curMenuPageId == 0 && curMenuType == 2) || (curMenuPageId == 1 && curMenuType == 0)) {
            // 所有视频
            setFocus('','','all_video_list_1',listDivClassName,1);
            setLeftMenuLi(curSelectedLi,(curMenuPageId+1));
          }else if ((curMenuPageId == 1 && curMenuType == 2) || (curMenuPageId == 2 && curMenuType == 0)) {
            // 热门赛事
            setFocus('','','hot_match_list_1',listDivClassName,1);
            setLeftMenuLi(curSelectedLi,(curMenuPageId+1));
          }else if ((curMenuPageId == 2 && curMenuType == 2) || (curMenuPageId == 3 && curMenuType == 0)) {
            // 主播大神
            setFocus('','','anchor_list_1',listDivClassName,1);
            setLeftMenuLi(curSelectedLi,(curMenuPageId+1));
          }else if ((curMenuPageId == 3 && curMenuType == 2) || (curMenuPageId == 4 && curMenuType == 0)) {
            // 精选专辑
            setFocus('','','album_list_1',listDivClassName,1);
            setLeftMenuLi(curSelectedLi,(curMenuPageId+1));
          }

          setFocus('leftmenu_li_'+curLiIdx,'left_menu_only_focused','','',0);
        }else {
          directionKeyFunc();
        }
        break;
      
      case 40: // 下
        curKey = 'd';
        if (curLiIdx != totalMenuLiNum && curActiveVideo.length == 0) { // 只有左边菜单栏有焦点时
          setLeftMenuLi(curLiIdx,(curLiIdx+1));

          for(var i = 0; i < speContainerIDs.length; i++){
            containersArr[i].style.display = 'none';
          }
          containersArr[curLiIdx].style.display = "block";
          // 设置focused
          setFocus('leftmenu_li_'+curLiIdx,'left_menu_only_focused','leftmenu_li_'+(curLiIdx+1),'left_menu_only_focused',2);
        }else if (curActiveVideo.length != 0) { // 左侧内容列表中有焦点
          directionKeyFunc();
        }
        break;
    }
  }

  // 设置leftmenu的焦点移动
  function setLeftMenuLi(removeLiIdx,addLiIdx){
    removeClass(getObjById('leftmenu_li_'+removeLiIdx),'left_menu_active');
    addClass(getObjById('leftmenu_li_'+addLiIdx),'left_menu_active');
  }

  // 记录当前详情页右侧list的总数
  var curListsTotalNum;
  // 上下左右触发事件
  function directionKeyFunc(){
    if (curMenuPageId == 0 && curMenuType == 0) { // 热门推荐
      optionRLFunc('re_',0);
    }else if ((curMenuPageId == 0 && curMenuType == 2) || (curMenuPageId == 1 && curMenuType == 0)) {
      optionRLFunc('all_video_list_',1);
      curListsTotalNum = allVideos.length;
    }else if ((curMenuPageId == 1 && curMenuType == 2) || (curMenuPageId == 2 && curMenuType == 0)) {
      optionRLFunc('hot_match_list_',2);
      curListsTotalNum = hotMatchs.length;
    }else if ((curMenuPageId == 2 && curMenuType == 2) || (curMenuPageId == 3 && curMenuType == 0)) {
      optionRLFunc('anchor_list_',2);
      curListsTotalNum = anchors.length;
    }else if ((curMenuPageId == 3 && curMenuType == 2) || (curMenuPageId == 4 && curMenuType == 0)) {
      optionRLFunc('album_list_',2);
      curListsTotalNum = albums.length;
    }
  }

  /*
   * 焦点在右侧详情页时的按左右键的方法
   *
   * listIDStr: 当前焦点的id
   * curMenuPageType: 当前选中的是menu的哪一个，0：热门，1：所有视频，2：其他
   */
  function optionRLFunc(listIDStr, curMenuPageType){
    var curIdx =  parseInt(curActiveVideo[0].id.replace(listIDStr,''));
    var curDivisor = curMenuPageType == 1 ? 4 : 5;
    // 热门
    if (curMenuPageType == 0) {
      if (curKey == 'r' || curKey == 'l') { // 左/右切换时
        var reMinMax = curKey == 'r' ? recommendArrs.length : 1;
        if (curIdx != reMinMax) {
          var closeIdx = curKey == 'r' ? (curIdx + 1) : (curIdx - 1);
          setFocus((listIDStr+curIdx),listDivClassName,(listIDStr+closeIdx),listDivClassName,2);
        }
        if (curIdx == 1 && curKey == 'l') {
          setFocus(listIDStr+curIdx,listDivClassName,'','',0);
          setFocus('','','leftmenu_li_'+curSelectedLi,'left_menu_only_focused',1);
        }
      }else {  // 上/下切换时
        if (curKey == 'u' && (curIdx == 5 || curIdx == 6 || curIdx == 7)) {
          setFocus((listIDStr+curIdx),listDivClassName,(listIDStr+1),listDivClassName,2);
        }else if (curKey == 'd' && (curIdx != 5 || curIdx != 6 || curIdx != 7)) {
          setFocus((listIDStr+curIdx),listDivClassName,(listIDStr+5),listDivClassName,2);
        }
      }
    }else { // 其他
      var curModValue = curKey == 'r' ? 0 : 1;
      var nextCloseIdx;
      if (curKey == 'r' || curKey == 'l') {
        nextCloseIdx = 1;
        if (curIdx % curDivisor != curModValue) {
          var rlCloseIdx = curKey == 'r' ? (curIdx + nextCloseIdx) : (curIdx - nextCloseIdx);
          setFocus((listIDStr+curIdx),listDivClassName,(listIDStr+rlCloseIdx),listDivClassName,2);
        }
        if ((curIdx % curDivisor == 1) && curKey == 'l') {
          setFocus((listIDStr+curIdx),listDivClassName,'','',0);
          scrollPage(0,0,1);
          setFocus('','','leftmenu_li_'+curSelectedLi,'left_menu_only_focused',1);
        }
      }else{ // 上/下
        nextCloseIdx = curMenuPageType == 1 ? 4 : 5;
        if (curKey == 'd') { // 向下的时候，如果下方没有内容，跳到下一行的第一个
          if (getObjById(listIDStr + (curIdx + nextCloseIdx)) == null) {
            // 所有视频
            if (curMenuPageType == 1) {
              if (curIdx % 4 == 2) {
                nextCloseIdx = 3;
              }else if (curIdx % 4 == 3) {
                nextCloseIdx = 2;
              }if (curIdx % 4 == 0) {
                nextCloseIdx = 1;
              }
            }else if (curMenuPageType == 2) { // 主播/专辑/热门赛事
              if (curIdx % 5 == 2) {
                nextCloseIdx = 4;
              }else if (curIdx % 5 == 3) {
                nextCloseIdx = 3;
              }if (curIdx % 5 == 4) {
                nextCloseIdx = 2;
              }if (curIdx % 5 == 0) {
                nextCloseIdx = 1;
              }
            }
          }
        }
        var udCloseIdx = curKey == 'd' ? (curIdx + nextCloseIdx) : (curIdx - nextCloseIdx);
        setFocus((listIDStr+curIdx),listDivClassName,(listIDStr+udCloseIdx),listDivClassName,2);

        scrollPage(udCloseIdx,curMenuPageType,0);
      }
    }
  }

/************************ 键盘触发事件 end ************************/

/************************ 滚屏事件 start ************************/
  /*
   * nextIdx: 焦点要移动到的下一个的idx
   * pageType: 页面类型：1：一行4个，2：一行5个
   * isClear: 为1时，右侧内容无焦点，页面回到顶部
   */
  function scrollPage(nextIdx,pageType,isClear){
    // 当前要滚动的div的id
    var containerID = firRowIds[curSelectedLi-1];
    // marginTop值
    var scrollMT;

    if (isClear == 1) {
      scrollMT = 0;
    }else {
      // 上/下 正/负
      var scrollVal = pageType == 1 ? -12.62 : -21.19;
      
      // 一行4/5个
      var divisor = pageType == 1 ? 4 : 5;

      // 开始滚动的行数
      var firScrollRow = pageType == 1 ? 4 : 3;      

      var totalRow = Math.ceil(curListsTotalNum / divisor);

      var nextRow = Math.ceil(nextIdx / divisor);

      if (nextRow >= firScrollRow && nextRow <= totalRow) {
        scrollMT = scrollVal * (nextRow - firScrollRow + 1);
      }else if (nextRow < firScrollRow) {
        scrollMT = 0;
      }
    }
    
    getObjById(containerID).style.marginTop = scrollMT + 'em';
  }
/************************ 滚屏事件 end ************************/


















